/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace DaveSexton.DocProject
{
	internal sealed class ExternalSourcesEditor : DocProjectOptionsDialogEditorBase<DocProjectOptions, ExternalSourcesEditorDialog>
	{
		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ExternalSourcesEditor" /> class.
		/// </summary>
		public ExternalSourcesEditor()
		{
		}
		#endregion

		#region Methods
		protected override ExternalSourcesEditorDialog CreateDialog(DocProjectOptions options, ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			if (options == null)
				throw new ArgumentNullException("options");

			Configuration.BuildEngineProvider engineProvider = options.Project.Provider;

			SourceCollection buffer = new SourceCollection(engineProvider.AllSupportedExternalSourceFileExtensions, options.ExternalSources);

			ExternalSourcesEditorDialog dialog = new ExternalSourcesEditorDialog(buffer, options.Project);
			dialog.CustomSourceFilter = engineProvider.CustomExternalSourcesAssemblyOrFileDialogFilter;
			dialog.UseAssemblyFilter = engineProvider.UseExternalSourcesAssemblyDialogFilter;

			return dialog;
		}

		protected override bool HandleChanges(DocProjectOptions options, ExternalSourcesEditorDialog form, System.Windows.Forms.DialogResult result)
		{
			if (result == System.Windows.Forms.DialogResult.OK && form.HasChanges)
			{
				options.ExternalSources = new SourceCollection(options.Project.Provider.AllSupportedExternalSourceFileExtensions, form.Sources);

				return true;
			}
			else
				return false;
		}

		protected override object GetValue(DocProjectOptions options, ExternalSourcesEditorDialog form, System.Windows.Forms.DialogResult result)
		{
			return options.ExternalSources;
		}
		#endregion
	}
}
